var express = require('express');
var router = express.Router();
var crypto = require('crypto');

//get方式传输数据
router.get('/', function(req, res, next) {

    res.render('usecrypto', { title: '加密字符串示例' });

});

// post方式传输数据
router.post('/', function (req, res) {

  var userName = req.body.txtUserName,
    userPwd = req.body.txtUserPwd;

  //生成口令的散列值
  var md5 = crypto.createHash('sha1');   //crypto模块功能是加密并生成各种散列
  var en_upwd = md5.update(userPwd).digest('hex');

  console.log('加密后的密码:'+en_upwd);

  res.render('usecrypto', { title: '提交表单及接收参数示例' });

});

module.exports = router;